package day14;

import java.util.ArrayList;

public class homework0004 extends Thread {
    homework00004 check;
    private ArrayList<String> arr;
    private static boolean flag;

    public homework0004(ArrayList<String> arr, homework00004 check) {
        this.arr = arr;
        this.check = check;
    }

    @Override
    public void run() {
        while (true) {
            synchronized (check.getlock()) {
                if (arr.size() == 0) {
                    break;
                } else {
                    if (check.isFlag()) {
                        String num = arr.remove(0);
                        System.out.print(num);
                        check.setFlag(false);
                        check.getlock().notify();
                    } else {
                        try {
                            check.getlock().wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }
}
